package com.imooc.springmvc.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.imooc.springmvc.entity.Form;

import java.util.List;

@RequestMapping("/form")
public class FormController {
    @PostMapping("/apply")
    @ResponseBody
    public String apply(@RequestParam(value="n", defaultValue = "ANON") String name, String course, Integer[] purpose) {
        System.out.println("name: " + name);
        System.out.println("course: " + course);
        System.out.println("purpose: " + purpose);
        return "apply";
    }

    @PostMapping("/apply2")
    @ResponseBody
    public String apply2(String name, String course, @RequestParam List<Integer> purpose) {
        System.out.println("name: " + name);
        System.out.println("course: " + course);
        for (Integer p : purpose) {
            System.out.println("purpose: " + p);
        }
        return "apply";
    }
    @PostMapping("/apply3")
    @ResponseBody
    public String apply3(Form form) {
        System.out.println("name: " + form.getName());
        System.out.println("course: " + form.getCourse());
        for (Integer p : form.getPurpose()) {
            System.out.println("purpose: " + p);
        }
        return "apply";
    }
    @PostMapping("/apply-delivery")
    @ResponseBody
    public String applyDelivery(Form form) {
        System.out.println("name: " + form.getName());
        System.out.println("course: " + form.getCourse());
        System.out.println("delivery name: " + form.getDelivery().getName());
        System.out.println("delivery address: " + form.getDelivery().getAddress());
        System.out.println("delivery mobile: " + form.getDelivery().getMobile());
        return "applyDelivery";
    }
}